<template>
  <div class="CadRightTabelCompontens">
    <div class="title">
      <!-- <span>{{ $t("message.msView.cadViewRightTab.layerChange") }}</span> -->
      <!-- <el-select v-model="optionValue" placeholder="请选择" class="option">
        <el-option
          v-for="item in optionList"
          :key="item.value"
          :label="item.label"
          :value="item.value"
        >
        </el-option>
      </el-select> -->
      <el-select v-model="selectMarkupFileId" :placeholder="$t('message.cadViewer.taggingMode.select_file')"
        class="option">
        <!-- :label="item.markUpFileName" -->
        <el-option v-for="item in markupFileDataList" :key="item.id" :label="item.name" :value="item.id"></el-option>
      </el-select>
    </div>
    <div class="title2">
      <el-button class="btn-edit" @click="onEditClick">
        {{ $t("message.msView.cadViewRightTab.markupEdit") }}
      </el-button>

      <el-button class="btn-refresh" @click="onRefreshClick">
        {{ $t("message.public.refresh") }}
      </el-button>
    </div>

    <el-table ref="singleTable" :data="layerDataList" style="width: 100%,height:100%"
      @selection-change="handleSelectionChange" :header-cell-style="{
        color: 'rgba(0, 0, 0, 0.85)',
        fontSize: '14px',
        textAlign: 'left',
        fontWeight: 'bold',
        padding: 0,
        height: '32px',
      }" :cell-style="{
        color: 'rgba(96,98,102,1)',
        fontSize: '14px',
        textAlign: 'left',
        padding: 0,
        height: '32px',
      }" :row-style="{
        color: 'rgba(96,98,102,1)',
        fontSize: '13px',
        textAlign: 'left',
        padding: 0,
        height: '32px',
      }">
      <el-table-column type="index" width="48" :label="$t('message.msView.cadViewRightTab.layerIndex')">
      </el-table-column>
      <el-table-column type="selection" width="46"> </el-table-column>
      <el-table-column prop="sName" :label="$t('message.msView.cadViewRightTab.layerName')" />

      <!-- </el-table-column> --> </el-table>
  </div>
</template>

<script>
import $ from "jquery";
export default {
  name: "CadRightTabelCompontens",
  props: {
    markupFileDataList: {
      type: Array,
      default: function () {
        return [];
      },
    },

    layerDataList: {
      type: Array,
      default: function () {
        return [];
      },
    },
  },

  watch: {
    markupFileDataList(val) {
      // debugger
      if (val.length > 0) {
        this.selectMarkupFileId = val[0].id;
      } else this.selectMarkupFileId = "";
    },

    selectMarkupFileId(val) {
      let re = null;
      for (var i = 0; i < this.markupFileDataList.length; i++) {
        if (this.markupFileDataList[i].id == val) {
          re = this.markupFileDataList[i];
          break;
        }
      }
      this.$emit("onMarkupFileSelect", re);
    },

    /**
     * 传入layerlist后，默认显示所有layer，layer默认选中
     */
    layerDataList(val) {
      this.$nextTick(() => {
        val.forEach((row) => {
          this.$refs.singleTable.toggleRowSelection(row);
        });
      });
    },
  },

  data() {
    return {
      selectMarkupFileId: "",

      optionList: [],
      optionValue: "",
      multipleSelection: [],
      tableData: [],
      tableHeight: 0,
    };
  },
  components: {},
  methods: {
    handleSelectionChange(e) {
      // debugger
      if (e == null) return;
      for (var i = 0; i < this.layerDataList.length; i++) {
        this.layerDataList[i].nState = 0;
        for (var j = 0; j < e.length; j++) {
          if (this.layerDataList[i].id == e[j].id) {
            this.layerDataList[i].nState = 1;
          }
        }
      }
      this.$emit("onShowLayerSelect", this.layerDataList);
    },

    onEditClick() {
      this.$emit("onEditClick", null);
    },

    onRefreshClick() {
      this.$emit("onRefreshClick", null);
    },
  },
  created() { },
  updated() {
    // 使用querySelectorAll选中所有带有.elx-cell--checkbox类的元素
    var elements = document.querySelectorAll('.elx-cell--checkbox');

    // 遍历这些元素  
    elements.forEach(function (element) {
      // 修改每个元素的title属性  
      element.setAttribute('title', '');
    })
  },
  mounted() {
    // debugger;

    let that = this;
    this.$nextTick(function () {
      this.tableHeight = $(".CadRightTabelCompontens").height() - 34;
      // window.onresize = () => {
      //   return (() => {
      //     that.tableHeight = $(".CadRightTabelCompontens").height() - 34;
      //   })();
      // };
      window.addEventListener("resize", () => {
        return (() => {
          that.tableHeight = $(".CadRightTabelCompontens").height() - 34;
        })();
      }, false);
    });
  },
  destroyed() {
    window.removeEventListener("resize", function () { });
  },
};
</script>
<style lang="scss" scoped>
.CadRightTabelCompontens {
  width: 218px;
  height: 100%;
  border-left: 1px solid #c9c9c9;
  background-color: #ffffff;
}

.title {
  padding: 8px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: #edeeef;
  font-size: 14px;
  height: 34px;
}

.title2 {
  padding: 4px 12px 8px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: #edeeef;
  font-size: 14px;
  height: 34px;

  button {
    width: 50% !important;
  }
}

.option {
  width: 100%;

  ::v-deep .el-input--suffix .el-input__inner {
    width: 100%;
    height: 28px;
  }

  ::v-deep .el-input__icon {
    line-height: 28px;
  }
}

.btn-edit {
  width: 45%;
  padding: 1px 0px;
  // background: #ffffff;
  border-radius: 4px;
  // border: 1px solid rgba(0, 0, 0, 0.15);
  text-align: center;
}

.btn-refresh {
  width: 45%;
  padding: 1px 0px;
  // background: #ffffff;
  border-radius: 4px;
  // border: 1px solid rgba(0, 0, 0, 0.15);
  text-align: center;
}
</style>
